package com.elong.qadev.entity;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import com.elong.qadev.tool.AESUtils;
import com.elong.qadev.tool.MD5Utils;

@Entity
@Table(name = "HTTP_NAMEVALUEPAIR", schema = "ti")
public class NameValuePair {
	
	private int id;
    private String key;
    private String value;
    private String encryption;
    private String secret;
    private String doc;
    private String comments;
    private int CaseId;
	@Column(name = "CASEID", nullable = false, length = 50)
	public int getCaseId() {
		return CaseId;
	}

	public void setCaseId(int caseId) {
		CaseId = caseId;
	}
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "ID", unique = true, nullable = false, length = 10)
    public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public NameValuePair() {
		super();
    }
	 public NameValuePair(int id, String key, String value, String encryption, String secret, String doc,
			String comments, int caseId) {
		super();
		this.id = id;
		this.key = key;
		this.value = value;
		this.encryption = encryption;
		this.secret = secret;
		this.doc = doc;
		this.comments = comments;
		CaseId = caseId;
	}

	@Column(name = "NAMEVALUEPAIR_KEY",nullable = true, length = 50)
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
    @Lob 
	@Basic(fetch = FetchType.LAZY) 
    @Column(name = "NAMEVALUEPAIR_VALUE",nullable = true)
    public String getValue() {
    	if ("NONE".equals(encryption)) {
            return value;
        } else if ("AES".equals(encryption)) {
            return AESUtils.encryptByKey(value, secret);
        } else if ("MD5".equals(encryption)) {
            return MD5Utils.encrypt(value);
        } else {
            return value;
        }
    }

    public void setValue(String value) {
        this.value = value;
    }
    
    @Column(name = "ENCRYPTION",nullable = true, length = 50)
    public String getEncryption() {
        return encryption;
    }

    public void setEncryption(String encryption) {
        this.encryption = encryption;
    }
    @Column(name = "NAMEVALUEPAIR_SECRET",nullable = true, length = 100)
    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }
    @Column(name = "DOC",nullable = true, length = 100)
    public void setDoc(String doc) {
        this.doc = doc;
    }

    public String getDoc() {
        return doc;
    }
    @Column(name = "COMMENTS",nullable = true, length = 100)
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }
    
}

